package com.g8.pethospitallearnbackend.controller;

import com.g8.pethospitallearnbackend.entity.Type;
import com.g8.pethospitallearnbackend.exception.CustomException;
import com.g8.pethospitallearnbackend.exception.NoDataException;
import com.g8.pethospitallearnbackend.service.TypeService;
import com.g8.pethospitallearnbackend.utils.responseUtil.ResponseStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/type")
public class TypeController {
    @Autowired
    private TypeService typeService;

    /**
     * 返回所有病种的名称
     * @return 病种名称的列表
     */
    @GetMapping("")
    public List<String> getAllTypeName(){
        List<Type> types=typeService.getAllTypes();
        if(types==null){
            throw new NoDataException(ResponseStatusEnum.DATA_NOT_EXIST);
        }
        List<String> rs=new ArrayList<>();
        for(Type type:types){
            rs.add(type.getTypeName());
        }
        return rs;
    }

}
